package com.test.japidocs.controller;

import com.test.japidocs.dto.UserDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户接口类
 */
@RequestMapping("/api")
@RestController
public class HelloController {

    /**
     * 获取所有的用户
     *
     * @param age 年龄
     * @return UserDTO
     */
    @GetMapping("/user")
    public UserDTO getUsers(@RequestParam int age) {
        UserDTO userDTO = new UserDTO();
        userDTO.setUsername("Cain");
        userDTO.setAge(26);
        return userDTO;
    }

    /**
     * 保存用户
     *
     * @param userDTO 用户对象
     * @return UserDTO
     */
    @PostMapping("/user")
    public UserDTO saveUser(@RequestBody UserDTO userDTO) {
        return userDTO;
    }

}
